import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/Layout'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home'
const Product = () => import('@/views/Product/index.vue')
const ProductList = () => import('@/views/Product/List')
const Category = () => import('@/views/Product/Category')
const Order = () => import('@/views/Order/')
const OrderList = () => import('@/views/Order/List')
const Collect = () => import('@/views/Order/Collect')
const Advert = () => import('@/views/Advert/index.vue')
const AdvertList = () => import('@/views/Advert/List')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        name: 'home',
        component: Home,
      },
      {
        path: '/product',
        name: 'product',
        component: Product,
        children: [
          {
            path: 'productlist',
            name: 'productlist',
            component: ProductList,
          },
          {
            path: 'category',
            name: 'category',
            component: Category,
          },
        ],
      },
      {
        path: '/order',
        name: 'order',
        component: Order,
        children: [
          {
            path: 'orderlist',
            name: 'orderlist',
            component: OrderList,
          },
          {
            path: 'collect',
            name: 'collect',
            component: Collect,
          },
        ],
      },
      {
        path: '/advert',
        name: 'advert',
        component: Advert,
        children: [
          {
            path: 'advertlist',
            name: 'advertlist',
            component: AdvertList,
          },
        ],
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  /* 在开发环境下，process.env.BASE_URL 通常为 /，此时路由配置如下：在这种情况下，访问 /home 就能正常访问到 Home 组件
  假设你要将项目部署到服务器的 /myapp 子目录下，Vue CLI 在构建时会自动将 process.env.BASE_URL 设置为 /myapp/。
  此时路由配置保持不变：但实际访问 Home 组件的路径就变成了 /myapp/home。
  通过使用 base: process.env.BASE_URL，你无需在开发和生产环境中手动修改路由的基础路径 */
  routes,
})

export default router
